<?php

/**
 * Copyright              [HD框架] (C)2011-2012 houdunwang ，Inc. 
 * Encoding               UTF-8 
 * @author                向军
 * Link                   http://www.houdunwang.com       
 * E-mail                 houdunwangxj@gmail.com
 */
class categoryControl extends commonControl {

    function index() {
        $db = M("category");
        $category = $db->field("catid,cname,sort,pid,mid")->all();
        $category = arr::channel($category, "catid", "pid", 0, 2, "&nbsp;&nbsp;&nbsp;&nbsp;");
        $this->assign("category", $category);
        $this->display();
    }
    //添加栏目
    function add_show() {
        $this->display();
    }

    //添加栏目
    function add() {
        $db = M("category");
        if ($db->add()) {
            $this->success("添加栏目成功");
        } else {
            $this->error("添加栏目失败");
        }
    }

    function del() {
        $catid = $_GET['catid'];
        $db = M("category");
        $result = $db->where("pid='$catid'")->find();
        if ($result) {
            $this->error("请先删除子目录");
        } else {
            if ($db->del($catid)) {
                $this->success("删除栏目成功");
            } else {
                $this->error("删除栏目失败，请重试");
            }
        }
    }

    //选择模板文件
    function selecttemplate() {
        C("debug",0);
        $path = C("tpl_index_dir") . '/' . C("tplstyle");
        $files = dir::tree($path, 'html');
        $this->assign("tplpath", $path);
        $this->assign("files", $files);
        $this->display();
    }

}

?>


